<?php
namespace app\index\controller;

use think\Controller;
use app\admin\model\NoteModel;

/**
 * 杂记
 * @author Alinejun666
 * Date 2018-8-20
 */
class Note extends controller
{
    public function index()
    {
    	$note = new NoteModel();

    	$where = ['status' => 1];
    	$order = "create_time desc";
    	$field = "*";
    	$info  = $note->get_order_info($where, $order, $field);

		return $this->fetch('index', ['data' => $info]);
    }


    public function all()
    {
    	$note = new NoteModel();

    	$where = ['status' => 1];
    	$order = "create_time desc";
    	$field = "*";
    	$list  = $note->get_list($where, $order, $field);
    	
    	$result = $arr = [];
    	foreach ($list as $k => $v) {
    		// 时间格式化
    		$v['date_time'] = date("M-d",strtotime($v['create_time']));

    		$mt = date("M-Y",strtotime($v['create_time']));
    		if (in_array($mt, $arr)) {
    			$i = array_search($mt, $arr);
				$result[$i]['list'][] = $v;
    		}else{
    			$arr[$k] = $mt;
	    		$result[$k]['month'] = $mt;
				$result[$k]['list'][] = $v;    			
    		}
    	}

		return $this->fetch('all', ['data' => $result]);
    }
}
